package com.zhkj.shixi.tvplayer.MusicPlayer;

import android.app.Activity;
import android.media.MediaPlayer;
import android.util.Log;

import com.zhkj.shixi.tvplayer.R;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class LrcController {
    public void start(File file, Activity activity, MediaPlayer mediaPlayer){
        String lrcStr = file.getAbsolutePath();
        LrcView lrcView = activity.findViewById(R.id.lrc);
        lrcView.setLrc(readFileByLines(lrcStr));
        lrcView.setPlayer(mediaPlayer);
        lrcView.init();
    }
    public static String readFileByLines(String fileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        String lrc = "";
        try {
            System.out.println("以行为单位读取文件内容，一次读一整行：");
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
                lrc+=tempString;
                lrc+="\n";
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        Log.w("LRC",lrc);
        return lrc;
    }
}
